package demo2;

import java.util.concurrent.CountDownLatch;

public class test {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch=new CountDownLatch(5);
        for (int i = 0; i < 9; i++) {
            int id=i;
            Thread t=new Thread(()->{
                System.out.println(id);
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
              countDownLatch.countDown();//通知当前任务完毕
            });
            t.start();
        }
        countDownLatch.await();//10个任务都执行完
        System.out.println("10个任务都完成了");
    }
}
